package com.bright.ghj.overt.constant;

import com.bright.ghj.common.util.StringUtil;
import com.bright.ghj.common.util.PropertiesUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @Author hxj
 * @Date 2024/1/24 14:42
 * @Description 全局配置参数
 */
@Configuration
@PropertySource("classpath:config/overt.properties")
public class DataConstantBak {

    /**
     * 是否启用财务数据
     */
    public final static boolean CW_ENABLE;
    /**
     * 财务数据表在openReportRecord中的category
     */
    public final static String CW_CATEGORY;

    /**
     * 是否启用党务数据
     */
    public final static boolean DW_ENABLE;
    /**
     * 党务数据表在openReportRecord中的category
     */
    public final static String DW_CATEGORY;

    /**
     * 是否启用事务数据
     */
    public final static boolean SW_ENABLE;
    /**
     * 事务数据表在openReportRecord中的category
     */
    public final static String SW_CATEGORY;

    /**
     * 用于配置Access导入时是使用jdk异步任务还是消息队列
     */
    public final static String ACCESS_IMPORT_QUALIFIER;

    /**
     * 数据加密存储类型 1：base64
     * TODO 未真正用上该常量
     */
    public final static Integer ENCRYPT_TYPE;

    /**
     * 表格总宽度 用于按比例分配fileItem的fieldLen
     */
    public final static Integer FILEITEM_TOTAL_WIDTH;

    static {
        // 读配置表给参数赋值
        CW_CATEGORY = PropertiesUtil.getValue("cw_category");
        DW_CATEGORY = PropertiesUtil.getValue("dw_category");
        SW_CATEGORY = PropertiesUtil.getValue("sw_category");
        CW_ENABLE = !StringUtil.equals(PropertiesUtil.getValue("cw_enable"), "0"); // 财务默认启用
        DW_ENABLE = StringUtil.equals(PropertiesUtil.getValue("dw_enable"), "1");
        SW_ENABLE = StringUtil.equals(PropertiesUtil.getValue("sw_enable"), "1");

        ACCESS_IMPORT_QUALIFIER = PropertiesUtil.getValue("access_import_qualifier");
        ENCRYPT_TYPE = getIntValue("encrypt_type", 1);
        FILEITEM_TOTAL_WIDTH = getIntValue("fileitem_total_width", 1500);
    }

    private static Integer getIntValue(String key, Integer defaultValue) {
        String stringValue = PropertiesUtil.getValue(key);
        if (stringValue == null) {
            return defaultValue;
        } else {
            return Integer.parseInt(stringValue);
        }
    }

}
